%option noyywrap
%option nounput
%option noinput

%{
#include <cstdlib>
#include <string>

#include "sysy.tab.hpp"

using namespace std;
%}

/* 空白符及行注释 */
WhiteSpace			[ \t\n\t]*
LineComment			"//".*
LinesComment		"/*"[^/]*"*/"

/* 标识符 */
Identifier 			[a-zA-Z_][a-zA-Z0-9_]*

/* 整数字面量 */
Decimal				[1-9][0-9]*
Octal				0[0-7]*
Hexadecimal			0[xX][0-9a-fA-F]+

%%
{WhiteSpace}		{ /* Do nothing */ }
{LineComment}		{ /* Do nothing */ }
{LinesComment}		{ /* Do nothing */ }

"int"				{ return INT; }
"return"			{ return RETURN; }
"if"				{ return IF; }
"else"				{ return ELSE; }

"const"				{ return CONST;  }
"<="				{ return LE; }
">="				{ return GE; }
"=="				{ return EQ; }
"!="				{ return NE; }
"&&"				{ return LAND; }
"||"				{ return LOR; }

{Identifier}		{ yylval.str_val = new string(yytext); return IDENT; }

{Decimal}			{ yylval.int_val = strtol(yytext, nullptr, 10); return INT_CONST; }
{Octal}				{ yylval.int_val = strtol(yytext, nullptr, 8); return INT_CONST; }
{Hexadecimal}		{ yylval.int_val = strtol(yytext, nullptr, 16); return INT_CONST; }

.					{ return yytext[0]; }

%%



